﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DMSoft;
using System.IO;

namespace Client
{
    public partial class ClientSettings : Form
    {
        public ClientSettings()
        {
            InitializeComponent();
        }

        private void apply_btn_Click(object sender, EventArgs e)
        {
            //serverAdress =  serverAddress_tbox.Text;
            //threadSleep = Convert.ToInt32(threadSleep_tbox.Text);

            StreamWriter settingsWriter = new StreamWriter("clientSettings.txt", false);
            settingsWriter.WriteLine(clientName_tbox.Text);
            settingsWriter.WriteLine(serverAdress_tbox.Text);
            if (radioButton2.Checked)
            {
                settingsWriter.WriteLine(threadCount_tbox.Text);
                settingsWriter.WriteLine("fixed");
                
            }
            else
            {
                settingsWriter.WriteLine("-1");
                settingsWriter.WriteLine("adaptive");
                
            }

            settingsWriter.Close();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void ClientSettings_Load(object sender, EventArgs e)
        {
           string[] settingsLines = File.ReadAllLines("clientSettings.txt");
           clientName_tbox.Text = settingsLines[0];
           serverAdress_tbox.Text = settingsLines[1];
           threadCount_tbox.Text = settingsLines[2];
         
            if ( settingsLines[3].Equals("fixed") )
           {

               radioButton2.Checked = true;    

           }
           else
           {
               radioButton1.Checked = true;
               threadCount_tbox.Enabled = false;
               threadCount_tbox.Text = ""; 
           }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

            threadCount_tbox.Enabled = true;

        }

        

        
        

        

        
      
    }
}
